<?php use_stylesheet('/enermaatik/tellimused.css') ?>
<?php use_stylesheet('/js/prompt/style.css') ?>
<?php use_javascript('/js/prompt/scripts.js') ?>
<?php slot('article') ?>
<?php include_component('memberzoneMenu', 'render') ?>
<?php include_component('headerMenu', 'breadCrumbs') ?>
<div class="clear"></div>
<div class="ccontentbox">
	<div class="ccontent">
		<div class="korvsisu">
			<h1><?php echo $node['pageTitle'] ?></h1>
			<div class="korvinfobox andmed">
				<div class="arvamusmenu">
					<div class="amenupealkiri toode">
						<p><?php echo __('Nimetus') ?></p>

					</div>
					<div class="amenupealkiri staatus">
						<p><?php echo __('Staatus') ?></p>
					</div>
					<div class="amenupealkiri kuupaev">
						<p><?php echo __('Kuupäev') ?></p>
					</div>
					<div class="amenupealkiri arve">

						<p><?php echo __('Arve nr') ?></p>
					</div>
					<div class="amenupealkiri tooted">
						<p><?php echo __('Tooted') ?></p>
					</div>
					<div class="amenupealkiri right">
						<p><?php echo __('Toimingud') ?></p>

					</div>
					<div class="clear"></div>
				</div>
				<?php foreach($orders as $order): ?>
				<div class="arvamuserow">
					<div class="rowsisu">
						<div class="andmecolumn">
							<p><a class="toode" id="order_<?php echo $order['id'] ?>" href="#"><?php echo $order['title'] ?></a></p>
						</div>

						<div class="andmecolumn center">
							<p><?php echo __($order['status'])?></p>
						</div>
						<div class="andmecolumn center">
							<p><?php echo $order['created_at']?></p>
						</div>
						<div class="andmecolumn center">
							<p><?php echo $order['order_number'] ?></p>
						</div>
						
						<div class="andmecolumn center">
							<?php foreach($order->OrederedItems as $item):?>
								<p><a target="_blank" href="<?php echo LinkGen::getInstance(LinkGen::PRODUCT)->link($item['id'],array()) ?>"><?php echo $item['name'] ?></a></p>
							<?php endforeach;?>
						</div>

						<div class="andmecolumn right">
							<p><a class="renamelink" href="#" title="<?php echo $order['id'] ?>"><?php echo __('Nimeta ümber') ?></a></p>
							<p><a href="<?php echo LinkGen::getInstance(LinkGen::STRUCTURE_ACTIONS)->link(null, array('module' => 'basketPage', 'action' => 'restartOrder', 'orderID' => $order['id'])) ?>"><?php echo __('Koosta uus') ?></a></p>
							<p><a href="<?php echo LinkGen::getInstance(LinkGen::STRUCTURE_ACTIONS)->link(null, array('module' => 'memberzoneOrders', 'action' => 'deleteOrder', 'orderID' => $order['id'])) ?>"><?php echo __('Eemalda') ?></a></p>
						</div>
						<div class="clear"></div>
					</div>
				</div>
				<?php endforeach; ?>
				<div class="clear"></div>
			</div>

		</div>
		<div class="ccontentmainbottom"></div>
		<div class="clear"></div>
	</div>
</div>

<!-- prompt HTML -->
<div id="rename_prompt_html" style="display:none">
<?php echo __("Enter order name")?>:<br />
	<input type="text" class="alertName" name="myname" value="" />
</div>

<script type="text/javascript">
// rename order
$('.renamelink, .ordername').click(function(){

	var promptSubmitCallback = function (v,m,f){
		// if "Cancel" was pressed => close prompt
		if(v === false){
			jQuery.prompt.close();
			return;
		}

		// get prompt input field
		var input = $('.alertName', m);

		// check if input prompt input is filled
		if(input.val() == ""){
			input.css("border","solid #ff0000 1px");
			return false;
		}else{ // if VALUE is OK, hide controls
			$('.jqibuttons').hide();
			$('.jqimessage').html('<?php echo __('Loading')?>...');
		}

		// request URL
		var url = '<?php echo LinkGen::getInstance(LinkGen::STRUCTURE_ACTIONS)->link(null, array('module' => 'memberzoneOrders', 'action' => 'renameOrder')) ?>';

		// send name change request
		$.get(url, {name: input.val(), orderID: v}, function(data) {
			$('#order_' + v).html(data.name);
			jQuery.prompt.close();
		},'json');

		return false;

	};

	$.prompt($("#rename_prompt_html").html(),{
		submit: promptSubmitCallback,
		buttons: { OK:$(this).attr('title'), Cancel: false }
	});
});
</script>
<?php end_slot() ?>

